package com.lsx143.wordcount.day2;

import com.lsx143.wordcount.bean.WaterSensor;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class MySource {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<WaterSensor> dss = env.addSource(new RandomWaterSensor(RandomWaterSensor.RUN_MODE.RANDOM));
        dss
                .flatMap(new FlatMapFunction<WaterSensor, String>() {
                    @Override
                    public void flatMap(WaterSensor waterSensor, Collector<String> collector) throws Exception {
                        if (waterSensor.getVc() >= 30) collector.collect(waterSensor.toString());
                    }
                })
                .print();
        env.execute();
    }
}
